package com.example.service.impl;

import com.example.entity.Teacher;
import com.example.entity.example.TeacherExample;
import com.example.mapper.TeacherMapper;
import com.example.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional(readOnly = true)
public class TeacherServiceImpl implements TeacherService {

    @Autowired(required = false)
    TeacherMapper teacherMapper;

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    public void add(Teacher teacher) {
        teacherMapper.insert(teacher);
    }

    @Override
    public Teacher getById(String id) {
        return teacherMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional
    public void updateById(Teacher teacher) {
        teacherMapper.updateByPrimaryKey(teacher);
    }

    @Override
    @Transactional
    public void updateSelectiveById(Teacher teacher) {
        teacherMapper.updateByPrimaryKeySelective(teacher);
    }

    @Override
    @Transactional
    public void removeById(String id) {
        teacherMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Teacher> getByExampleWithLimit(TeacherExample example, Integer page, Integer limit) {
        int begin = (page - 1) * limit;
        return teacherMapper.selectByExampleWithLimit(example, begin, limit);
    }

    @Override
    public long getCountByExample(TeacherExample example) {
        return teacherMapper.countByExample(example);
    }
}
